package com.shanshi.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanshi.activity.R;
import com.shanshi.activity.response.Bills;

import java.util.List;

/**
 * Created by scx on 2017/3/18.
 */

public class BillDetailAdapter extends BaseAdapter {

    private Context context;
    private List<Bills.Data> list;
    private LayoutInflater from;
    private ViewHolder holder=null;

    /*********存放账单列表每一个item的组件类**********/
    private static class ViewHolder{

        TextView textPay;  //交易类型
        TextView textStore;   //操作店铺的名称
        TextView textSum;   //操作金额
        TextView textTime;  //操作时间

    }

    public BillDetailAdapter(Context context, List<Bills.Data> list) {
        from = LayoutInflater.from(context);
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null) {
            convertView=from.inflate( R.layout.billdetailitmes, null);
            holder=new ViewHolder();
            holder.textPay=(TextView) convertView.findViewById(R.id.textPay);
            holder.textStore=(TextView) convertView.findViewById(R.id.textStore);
            holder.textSum=(TextView) convertView.findViewById(R.id.textSum);
            holder.textTime=(TextView) convertView.findViewById(R.id.textTime);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder) convertView.getTag();
        }

        switch (list.get(position).getType()){
            case 0:
                holder.textPay.setText("支付");
                holder.textSum.setText("-"+list.get(position).getMoney());
                holder.textSum.setTextColor(0xff99ca3c);
                break;
            case 1:
                holder.textPay.setText("充值");
                holder.textSum.setText("+"+list.get(position).getMoney());
//                holder.textSum.setTextColor();
                break;
            case 2:
                holder.textPay.setText("退款");
                holder.textSum.setText("+"+list.get(position).getMoney());
                break;
            case 3:
                holder.textPay.setText("提现");
                holder.textSum.setText(""+list.get(position).getMoney());
                break;
        }
        holder.textStore.setText(list.get(position).getShopName());
        holder.textTime.setText(list.get(position).getTime());
        return convertView;
    }
}
